package com.rzgeo.wcgallay.model;

import android.content.Context;

import com.rzgeo.rzmaplib.util.RmlUtil;
import com.rzgeo.wcgallay.util.WcmUtil;

import java.io.File;

/**
 * Created by zhanghang on 2018/2/6.
 */

public class WcmShapefileHelper {
    public final File shpFile;
    public final File cpgFile;
    public final File dbfFile;
    public final File prjFile;
    public final File shxFile;
    private final String _nameWithoutExt;
    public final String title;

    public WcmShapefileHelper(File parent,String nameWithoutExt,String title){
        this.title =title;
        _nameWithoutExt=nameWithoutExt;
        this.cpgFile =  RmlUtil.Files.join(parent,nameWithoutExt+".cpg");
        this.dbfFile =  RmlUtil.Files.join(parent,nameWithoutExt+".dbf");

        this.prjFile =  RmlUtil.Files.join(parent,nameWithoutExt+".prj");
        this.shpFile =  RmlUtil.Files.join(parent,nameWithoutExt+".shp");
        this.shxFile =  RmlUtil.Files.join(parent,nameWithoutExt+".shx");
    }

    public boolean exists(){
        return
                cpgFile.exists()&&
                shpFile.exists()&&
                dbfFile.exists()&&
                prjFile.exists()&&
                shxFile.exists();
    }

    public boolean initFromAssests(Context context,String assetsParentPath){
        return
                WcmUtil.Files.CopyAssets(context,assetsParentPath+File.separator+_nameWithoutExt+".cpg",cpgFile.getAbsolutePath())&&
                        WcmUtil.Files.CopyAssets(context,assetsParentPath+File.separator+_nameWithoutExt+".dbf",dbfFile.getAbsolutePath())&&
                        WcmUtil.Files.CopyAssets(context,assetsParentPath+File.separator+_nameWithoutExt+".prj",prjFile.getAbsolutePath())&&
                        WcmUtil.Files.CopyAssets(context,assetsParentPath+File.separator+_nameWithoutExt+".shp",shpFile.getAbsolutePath())&&
                        WcmUtil.Files.CopyAssets(context,assetsParentPath+File.separator+_nameWithoutExt+".shx",shxFile.getAbsolutePath());
    }
}
